package com.sgj.observer;

import lombok.extern.slf4j.Slf4j;

/**
 * 穿衣建议组件
 * @Author: Guoji Shen
 * @Date: 2022/11/7 14:06
 */
@Slf4j
public class WearView implements MyObserver {

    @Override
    public void update(Subject subject) {
        // 确定目标对象为 Weather 类，才获取新状态
        if (subject instanceof Weather) {
            Weather weather = (Weather) subject;
            float temperature = weather.getTemperature();
            if (temperature < 0) {
                log.info("穿衣建议 View:气温零下，请尽量避免出行");
            } else if (temperature < 10) {
                log.info("穿衣建议 View:十分寒冷，请穿羽绒服");
            } else if (temperature < 20) {
                log.info("穿衣建议 View:比较凉爽，可以披件外套");
            } else if (temperature < 30) {
                log.info("穿衣建议 View:比较温暖，可以穿薄点");
            } else {
                log.info("穿衣建议 View:非常炎热，请注意防晒");
            }
        }
    }
}